package com.nana.framework.MVC.model
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	public class ModelData extends EventDispatcher
	{
		protected var _dataMap:Object;
		
		public function ModelData(target:IEventDispatcher=null)
		{
			super(target);
			this._dataMap = {};
		}
		
		public function sendEvent(eventName:String, data:Object):void{
			dispatchEvent(new ModelEvent(eventName, data));
		}
		
		public function addDataListener(type:String, handler:Function, _arg3:Boolean=false):void{
			this.addEventListener(type, handler, false, 0, true);
			if (!_arg3){
				return;
			}
			var data:Object = this.getData(type);
			if (data != null){
				this.sendEvent(type, data);
			}
		}
		
		public function removeDataListener(type:String, handler:Function):void{
			this.removeEventListener(type, handler);
		}
		
		public function setData(type:String, data:Object):Object{
			this._dataMap[type] = data;
			this.sendEvent(type, data);
			return data;
		}
		
		public function insertData(type:String, data:Object):Object{
			this._dataMap[type] = data;
			return data;
		}
		
		public function getData(type:String):Object{
			return (this._dataMap[type]);
		}
		
		public function hasData(type:String):Boolean{
			return (this._dataMap.hasOwnProperty(type));
		}
	}
}